package com.testmanager.testmananger.practiseDemo.taskWork;


import lombok.Data;
import lombok.extern.slf4j.Slf4j;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

import java.time.LocalDate;

@Slf4j
@Configuration
public class DayEndConunt {




    @Bean
    public DayEnd getDayEnd(){
        return new DayEnd();
    }



    class DayEnd{
         private LocalDate localDate;
         private int status;  // 1 正常  2 异常  3 日终中

         DayEnd(){
             this.localDate = LocalDate.now();
             this.status = 1;
         }



         public LocalDate getLocalDate(){

             return this.localDate;
         }
         public int getStatus(){
             return this.status;
         }

         public void dayAddTemp(){
             log.info("localdate:{}",localDate);
             localDate = this.localDate.plusDays(1);

             log.info("localdate:{}",localDate);
         }


         public  void dayAdd() throws Exception {
             log.info("dayadd:{},{}",this.localDate,this.status);
         if (status == 1){
             synchronized (this){
                 status = 3;
                 Thread.sleep(10000);
                 int random = (int)(Math.random()*100);
                 log.info("random:{}",random);
                 if (random < 80){
                     status = 1;
                     localDate = this.localDate.plusDays(1);
                 }else {
                     status = 2;
                 }
             }

             }
             log.info("dayadd:{},{}",this.localDate,this.status);

         }


         public int repairDayEnd(){
             if (status == 2){
                 status =1 ;
                 return status;
             }

             return status;
         }


    }

}
